export function getOuterHTML(el) {
  if (el.outerHTML) {
    return el.outerHTML;
  } else {
    const container = document.createElement("div");
    container.appendChild(el.cloneNode(true));
    return container.innerHTML;
  }
}

// vue的源码中的 parsePath 函数
const parsePath = function (key) {
  const args = key.split('.');
  return function (obj) {
    for (let i = 0; i < args.length; i++) {
      if (!obj) return;
      obj = obj[args[i]];
    }
    return obj;
  };
};

export function getObjValue(obj, key) {
  // console.log(obj, key)
  key = key.substring(key.indexOf('.') + 1);
  return parsePath(key)(obj);
}
// console.log(getObjValue(obj, 'obj.boy.hobbly.play'));


export function isReservedTag(tagName) {
  const tags = 'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
    'div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,' +
    'a,b,abbr,bdi,bdo,br,cite,code,em,i,kbd,mark,q,' +
    's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +
    'embed,object,param,source,canvas,script,noscript,del,ins,' +
    'caption,col,colgroup,table,thead,tbody,td,th,tr,' +
    'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +
    'output,progress,select,textarea'; // 等等表示是标签
  const set = {};
  tags.split(",").forEach((tag) => {
    set[tag.trim()] = true;
  });
  return set[tagName.toLowerCase()];
}